package simple.framework.util;

import simple.framework.util.dbc.*;
import java.io.*;
import java.net.URL;
import java.net.URLConnection;
import java.net.Socket;
import java.util.Date;
import java.util.regex.*;

public class common {

    public conf conf;

    public String curl(String argBaseurl, String argUrl) {
        String tmpstr = "";
        String tBaseurl = argBaseurl;
        String tUrl = argUrl;
        if (!cls.isEmpty(tUrl)) {
            if (cls.getLeft(tUrl, 1).equals("/")) {
                tmpstr = tUrl;
            } else {
                if (cls.isEmpty(tBaseurl) || cls.getRight(tBaseurl, 1).equals("/")) {
                    tmpstr = tBaseurl + tUrl;
                } else {
                    tmpstr = tBaseurl + "/" + tUrl;
                }
            }
        }
        return tmpstr;
    }

    public String crValcodeTpl(String argString) {
        String tmpstr = "";
        String tString = argString;
        String tnvalidate = conf.sp.itake("global.config.nvalidate", "cfg");
        tmpstr = crValHtml(tString, tnvalidate, "{@valcode@}");
        return tmpstr;
    }

    public String crValHtml(String argTpl, String argVal, String argRecurrence) {
        String tmpstr = "";
        String tmpastr, tmprstr;
        String tTpl = argTpl;
        String tVal = argVal;
        String tRecurrence = argRecurrence;
        tmpstr = tTpl;
        tmprstr = "";
        tmpastr = cls.ctemplate(tmpstr, tRecurrence);
        if (tVal.equals("1")) {
            tmprstr = tmpastr;
        }
        tmpstr = cls.ctemplates(tmpstr, tRecurrence, tmprstr);
        return tmpstr;
    }

    public Boolean ckValcode(String argString) {
        Boolean tbool = false;
        String tString1 = argString;
        String tString2 = (String) conf.session.getAttribute("valcode");
        if (!cls.isEmpty(tString2)) {
            tString1 = cls.getString(tString1);
            tString2 = cls.getString(tString2);
            tString1 = tString1.toLowerCase();
            tString2 = tString2.toLowerCase();
            if (tString1.equals(tString2)) {
                tbool = true;
            }
        }
        return tbool;
    }

    public Boolean ckValcodes(String argString) {
        Boolean tbool = true;
        String tString = argString;
        String tnvalidate = conf.sp.itake("global.config.nvalidate", "cfg");
        if (tnvalidate.equals("1")) {
            tbool = ckValcode(tString);
        }
        return tbool;
    }

    public Integer dataDelete(String argDatabase, String argIdfield, String argId) {
        Integer tInteger = 0;
        String tDatabase = argDatabase;
        String tIdfield = argIdfield;
        String tId = argId;
        tInteger = dataDelete(tDatabase, tIdfield, tId, "");
        return tInteger;
    }

    public Integer dataDelete(String argDatabase, String argIdfield, String argId, String argOsql) {
        String tdatabase = cls.getString(argDatabase);
        String tidfield = cls.getString(argIdfield);
        String tid = cls.getString(argId);
        String tosql = cls.getString(argOsql);
        Integer tnum = -101;
        if (cls.cidary(tid)) {
            String tsqlstr = "delete from " + tdatabase + " where " + tidfield + " in (" + tid + ")";
            if (!cls.isEmpty(tosql)) {
                tsqlstr += tosql;
            }
            dbc tDbc = db.newInstance(conf);
            tnum = tDbc.Executes(tsqlstr);
        }
        return tnum;
    }

    public Integer dataSwitch(String argDatabase, String argField, String argIdfield, String argId) {
        Integer tInteger = 0;
        String tDatabase = argDatabase;
        String tField = argField;
        String tIdfield = argIdfield;
        String tId = argId;
        tInteger = dataSwitch(tDatabase, tField, tIdfield, tId, "");
        return tInteger;
    }

    public Integer dataSwitch(String argDatabase, String argField, String argIdfield, String argId, String argOsql) {
        String tdatabase = cls.getString(argDatabase);
        String tfield = cls.getString(argField);
        String tidfield = cls.getString(argIdfield);
        String tid = cls.getString(argId);
        String tosql = cls.getString(argOsql);
        Integer tnum = -101;
        if (cls.cidary(tid)) {
            String tsqlstr = "update " + tdatabase + " set " + tfield + "=abs(" + tfield + "-1) where " + tidfield + " in (" + tid + ")";
            if (!cls.isEmpty(tosql)) {
                tsqlstr += tosql;
            }
            dbc tDbc = db.newInstance(conf);
            tnum = tDbc.Executes(tsqlstr);
        }
        return tnum;
    }

    public Boolean directoryDelete(String argPath) {
        Boolean tbool = true;
        String tPath = argPath;
        File tFilePath = new File(tPath);
        if (tFilePath.exists() && tFilePath.isDirectory()) {
            File[] tlistFiles = tFilePath.listFiles();
            for (int ti = 0; ti < tlistFiles.length; ti++) {
                if (tlistFiles[ti].isFile()) {
                    if (!tlistFiles[ti].delete()) {
                        tbool = false;
                    }
                }
                if (tlistFiles[ti].isDirectory()) {
                    if (!directoryDelete(tlistFiles[ti].toString())) {
                        tbool = false;
                    }
                }
            }
            if (!tFilePath.delete()) {
                tbool = false;
            }
        }
        return tbool;
    }

    public Boolean directoryCreate(String argPath) {
        Boolean tbool = false;
        String tPath = argPath;
        File tFilePath = new File(tPath);
        if (tFilePath.exists() && tFilePath.isDirectory()) {
            tbool = true;
        } else {
            try {
                tFilePath.mkdirs();
                tbool = true;
            } catch (Exception e) {
            }
        }
        return tbool;
    }

    public Boolean directoryCreateNew(String argPath) {
        Boolean tbool = false;
        String tPath = argPath;
        File tFilePath = new File(tPath);
        if (!(tFilePath.exists() && tFilePath.isDirectory())) {
            try {
                tFilePath.mkdirs();
                tbool = true;
            } catch (Exception e) {
            }
        }
        return tbool;
    }

    public Boolean directoryExists(String argPath) {
        Boolean tbool = false;
        String tPath = argPath;
        File tFilePath = new File(tPath);
        if (tFilePath.exists() && tFilePath.isDirectory()) {
            tbool = true;
        }
        return tbool;
    }

    public Boolean directoryMove(String argPath1, String argPath2) {
        Boolean tbool = false;
        String tPath1 = argPath1;
        String tPath2 = argPath2;
        File tFilePath1 = new File(tPath1);
        File tFilePath2 = new File(tPath2);
        if ((tFilePath1.exists() && tFilePath1.isDirectory()) && !(tFilePath2.exists() && tFilePath2.isDirectory())) {
            if (tFilePath1.renameTo(tFilePath2)) {
                tbool = true;
            }
        }
        return tbool;
    }

    public Boolean fileCreate(String argFilePath, byte[] argContents) {
        Boolean tbool = true;
        String tFilePath = argFilePath;
        byte[] tContents = argContents;
        try {
            FileOutputStream tFileOutputStream = new FileOutputStream(tFilePath);
            tFileOutputStream.write(tContents);
            tFileOutputStream.close();
        } catch (Exception e) {
            tbool = false;
        }
        return tbool;
    }

    public Boolean fileExists(String argPath) {
        Boolean tbool = false;
        String tPath = argPath;
        File tFilePath = new File(tPath);
        if (tFilePath.exists() && tFilePath.isFile()) {
            tbool = true;
        }
        return tbool;
    }

    public Boolean fileDelete(String argPath) {
        Boolean tbool = true;
        String tPath = argPath;
        File tFilePath = new File(tPath);
        if (tFilePath.exists() && tFilePath.isFile()) {
            if (!tFilePath.delete()) {
                tbool = false;
            }
        }
        return tbool;
    }

    public String fileGetContents(String argFilePath) {
        String tmpstr = "";
        String tFilePath = argFilePath;
        try {
            FileInputStream tFileInputStream = new FileInputStream(tFilePath);
            InputStreamReader tInputStreamReader = new InputStreamReader(tFileInputStream, conf.charset);
            BufferedReader tBufferedReader = new BufferedReader(tInputStreamReader);
            while (true) {
                String tLine = tBufferedReader.readLine();
                if (tLine == null) {
                    break;
                } else {
                    tmpstr += tLine + "\r\n";
                }
            }
            if (!cls.isEmpty(tmpstr)) {
                tmpstr = cls.getLRStr(tmpstr, "\r\n", "leftr");
            }
        } catch (Exception e) {
            tmpstr = null;
        }
        return tmpstr;
    }

    public String fileGetHttpContents(String argURL, String argEncode) {
        String tmpstr = "";
        String tURL = argURL;
        String tEncode = argEncode;
        try {
            URL tURLObj = new URL(tURL);
            URLConnection tURLConnection = tURLObj.openConnection();
            InputStreamReader tInputStreamReader = new InputStreamReader(tURLConnection.getInputStream(), tEncode);
            BufferedReader tBufferedReader = new BufferedReader(tInputStreamReader);
            while (true) {
                String tLine = tBufferedReader.readLine();
                if (tLine == null) {
                    break;
                } else {
                    tmpstr += tLine + "\r\n";
                }
            }
            if (!cls.isEmpty(tmpstr)) {
                tmpstr = cls.getLRStr(tmpstr, "\r\n", "leftr");
            }
        } catch (Exception e) {
            tmpstr = null;
        }
        return tmpstr;
    }

    public Boolean filePutContents(String argFilePath, String argContents) {
        Boolean tbool = true;
        String tFilePath = argFilePath;
        String tContents = argContents;
        try {
            FileOutputStream tFileOutputStream = new FileOutputStream(tFilePath);
            tFileOutputStream.write(tContents.getBytes(conf.charset));
            tFileOutputStream.close();
        } catch (Exception e) {
            tbool = false;
        }
        return tbool;
    }

    public String getAdminTheme() {
        String tmpstr = "";
        tmpstr = conf.getActualRoute(conf.adminFolder);
        tmpstr += "/" + conf.imagesRoute + "/theme/";
        tmpstr += conf.sp.itake("global." + conf.adminFolder + ":config.theme", "cfg") + "/";
        return tmpstr;
    }

    public String[][] getFileList(String argPath) {
        String tPath = argPath;
        String[][] tmpAry = null;
        File tDirectoryFile = new File(conf.application.getRealPath(conf.getMapPath(tPath)).toString());
        File[] tlistFiles = tDirectoryFile.listFiles();
        for (int ti = 0; ti < tlistFiles.length; ti++) {
            if (tlistFiles[ti].isFile()) {

                String tDirName = tlistFiles[ti].getName();
                String tDirSize = cls.toString(tlistFiles[ti].length());
                Date tDirlastModified = new Date(tlistFiles[ti].lastModified());
                String tDirTime = cls.formatDate(tDirlastModified);
                String[][] tAry = new String[1][3];
                tAry[0][0] = tDirName;
                tAry[0][1] = tDirSize;
                tAry[0][2] = tDirTime;
                tmpAry = cls.mergeAry(tmpAry, tAry);
            }
        }
        return tmpAry;
    }

    public Long getFolderSize(String argPath) {
        Long tSize = 0L;
        String tPath = argPath;
        File tDirectoryFile = new File(conf.application.getRealPath(conf.getMapPath(tPath)).toString());
        File[] tlistFiles = tDirectoryFile.listFiles();
        for (int ti = 0; ti < tlistFiles.length; ti++) {
            if (tlistFiles[ti].isFile()) {
                tSize += tlistFiles[ti].length();
            }
            if (tlistFiles[ti].isDirectory()) {
                tSize += getFolderSize(tPath + tlistFiles[ti].getName() + "/");
            }
        }
        return tSize;
    }

    public String[][] getFolderList(String argPath) {
        String tPath = argPath;
        String[][] tFolderList = null;
        tFolderList = getFolderList(tPath, 1);
        return tFolderList;
    }

    public String[][] getFolderList(String argPath, Integer argCSize) {
        String tPath = argPath;
        Integer tCSize = argCSize;
        String[][] tmpAry = null;
        File tDirectoryFile = new File(conf.application.getRealPath(conf.getMapPath(tPath)).toString());
        File[] tlistFiles = tDirectoryFile.listFiles();
        for (int ti = 0; ti < tlistFiles.length; ti++) {
            if (tlistFiles[ti].isDirectory()) {
                String tDirSize = "-1";
                String tDirName = tlistFiles[ti].getName();
                Date tDirlastModified = new Date(tlistFiles[ti].lastModified());
                String tDirTime = cls.formatDate(tDirlastModified);
                if (tCSize == 1) {
                    tDirSize = cls.toString(getFolderSize(tPath + tDirName + "/"));
                }
                String[][] tAry = new String[1][3];
                tAry[0][0] = tDirName;
                tAry[0][1] = tDirSize;
                tAry[0][2] = tDirTime;
                tmpAry = cls.mergeAry(tmpAry, tAry);
            }
        }
        return tmpAry;
    }

    public String[][] getJtbcElement(String argId) {
        String tId = argId;
        String[][] tJtbcElement = null;
        String[][] tJtbcElementAry = conf.njtbcelement;
        if (tJtbcElementAry != null) {
            Integer tAry1Length0 = tJtbcElementAry.length;
            Integer tAry1Length1 = tJtbcElementAry[0].length;
            if (tAry1Length0 >= 1 && tAry1Length1 == 2) {
                for (int ti = 0; ti < tAry1Length0; ti++) {
                    String tJtbcElementPara = tJtbcElementAry[ti][0];
                    String tJtbcElementContent = tJtbcElementAry[ti][1];
                    if (cls.getParameter(tJtbcElementPara, "id").equals(tId)) {
                        tJtbcElement = new String[1][2];
                        tJtbcElement[0][0] = tJtbcElementPara;
                        tJtbcElement[0][1] = tJtbcElementContent;
                        break;
                    }
                }
            }
        }
        return tJtbcElement;
    }

    public String getRsValue(String argType, String argKeys) {
        String tType = argType;
        String tKeys = argKeys;
        String tmpstr = "";
        Object[][] tAry = null;
        if (tType.equals("rs")) {
            tAry = conf.rsAry;
        } else if (tType.equals("rsb")) {
            tAry = conf.rsbAry;
        } else if (tType.equals("rsc")) {
            tAry = conf.rscAry;
        } else if (tType.equals("rst")) {
            tAry = conf.rstAry;
        }
        if (tAry != null) {
            for (int ti = 0; ti < tAry.length; ti++) {
                if (cls.toString(tAry[ti][0]).equals(tKeys)) {
                    tmpstr = cls.toString(tAry[ti][1]);
                    break;
                }
            }
        }
        return tmpstr;
    }

    public String getSearchOptions(String argKeys) {
        String tKeys = argKeys;
        String tmpstr = "";
        if (!cls.isEmpty(tKeys)) {
            String tmptstr = "";
            String[] tKeysAry = tKeys.split(Pattern.quote(","));
            String tOptionUnselect = conf.sp.itake("global.tpl_config.option_unselect", "tpl");
            for (int ti = 0; ti < tKeysAry.length; ti++) {
                tmptstr = tOptionUnselect;
                tmptstr = tmptstr.replace("{$explain}", conf.sp.itake("global.sel_search." + encode.htmlencode(tKeysAry[ti]), "sel"));
                tmptstr = tmptstr.replace("{$value}", encode.htmlencode(tKeysAry[ti]));
                tmpstr += tmptstr;
            }
        }
        return tmpstr;
    }

    public String getSwitchOptions(String argKeys) {
        String tKeys = argKeys;
        String tmpstr = "";
        if (!cls.isEmpty(tKeys)) {
            String tmptstr = "";
            String[] tKeysAry = tKeys.split(Pattern.quote(","));
            String tOptionUnselect = conf.sp.itake("global.tpl_config.option_unselect", "tpl");
            for (int ti = 0; ti < tKeysAry.length; ti++) {
                tmptstr = tOptionUnselect;
                tmptstr = tmptstr.replace("{$explain}", conf.sp.itake("global.sel_switch." + encode.htmlencode(tKeysAry[ti]), "sel"));
                tmptstr = tmptstr.replace("{$value}", encode.htmlencode(tKeysAry[ti]));
                tmpstr += tmptstr;
            }
        }
        return tmpstr;
    }

    public Integer getTopID(String argDatabase, String argIdfield) {
        Integer tTopID = -1;
        String tDatabase = argDatabase;
        String tIdfield = argIdfield;
        dbc tDbc = db.newInstance(conf);
        String tsqlstr = "select max(" + tIdfield + ") from " + tDatabase;
        Object[] tArys = tDbc.getDataAry(tsqlstr);
        if (tArys != null) {
            tTopID = cls.getNum(cls.toString(tDbc.getValue((Object[][]) tArys[0], 0)), 0);
        }
        return tTopID;
    }

    public String getLngID(String argLngText) {
        String tLngText = argLngText;
        String tmpstr = "";
        String[][] tAry = conf.sp.itakes("global.sel_lng.all", "sel");
        for (int ti = 0; ti < tAry.length; ti++) {
            String tValue = tAry[ti][0];
            if (tValue.indexOf(":") != -1) {
                String[] tValueAry = tValue.split(Pattern.quote(":"));
                if (tValueAry.length == 2) {
                    if (tValueAry[0].equals(tLngText)) {
                        tmpstr = tValueAry[1];
                        break;
                    }
                }
            }
        }
        return tmpstr;
    }

    public String getLngText(String argLngID) {
        String tLngID = argLngID;
        String tmpstr = "";
        String[][] tAry = conf.sp.itakes("global.sel_lng.all", "sel");
        for (int ti = 0; ti < tAry.length; ti++) {
            String tValue = tAry[ti][0];
            if (tValue.indexOf(":") != -1) {
                String[] tValueAry = tValue.split(Pattern.quote(":"));
                if (tValueAry.length == 2) {
                    if (tValueAry[1].equals(tLngID)) {
                        tmpstr = tValueAry[0];
                        break;
                    }
                }
            }
        }
        return tmpstr;
    }

    public String itransferITakes(String argStrings) {
        String tmpstr = "";
        String tmpastr, tmprstr, tmptstr;
        String tStrings = argStrings;
        String tXInfostr = cls.getParameter(tStrings, "xinfostr");
        String tXInfoType = cls.getParameter(tStrings, "xinfotype");
        String tXInfolimit = cls.getParameter(tStrings, "xinfolimit");
        String tTpl = cls.getParameter(tStrings, "tpl");
        String tTplId = cls.getParameter(tStrings, "tplid");
        String tTplStr = cls.getParameter(tStrings, "tplstr");
        String tGenre = cls.getParameter(tStrings, "genre");
        String tOcmode = cls.getParameter(tStrings, "ocmode");
        String tBaseurl = cls.getParameter(tStrings, "baseurl");
        String tvars = cls.getParameter(tStrings, "vars");
        if (!cls.isEmpty(tXInfostr)) {
            String tNGenre = conf.getNGenre();
            if (cls.isEmpty(tBaseurl)) {
                if (!cls.isEmpty(tGenre) && !tGenre.equals(tNGenre)) {
                    tBaseurl = conf.getActualRoute(tGenre);
                    if (!cls.getRight(tBaseurl, 1).equals("/")) {
                        tBaseurl += "/";
                    }
                }
            }
            if (cls.isEmpty(tGenre)) {
                tGenre = tNGenre;
            }
            //**********************************************************************//
            if (!cls.isEmpty(tTplStr)) {
                tmpstr = tTplStr;
            } else {
                if (!cls.isEmpty(tTplId)) {
                    String[][] tJtbcElement = getJtbcElement(tTplId);
                    if (tJtbcElement != null) {
                        if (tJtbcElement[0].length == 2) {
                            tmpstr = tJtbcElement[0][1];
                        }
                    }
                } else {
                    if (tTpl.indexOf(".") != -1) {
                        tmpstr = conf.sp.itake(tTpl, "tpl");
                    } else {
                        tmpstr = conf.sp.itake("global.tpl_transfer." + tTpl, "tpl");
                    }
                }
            }
            if (!cls.isEmpty(tvars)) {
                String[] tvarsAry = tvars.split(Pattern.quote("|"));
                for (int ti = 0; ti < tvarsAry.length; ti++) {
                    String tvarsAryStr = tvarsAry[ti];
                    if (!cls.isEmpty(tvarsAryStr)) {
                        String[] tvarsAryStrAry = tvarsAryStr.split(Pattern.quote("="));
                        if (tvarsAryStrAry.length == 2) {
                            tmpstr = tmpstr.replace("{$" + tvarsAryStrAry[0] + "}", tvarsAryStrAry[1]);
                        }
                    }
                }
            }
            //**********************************************************************//
            Integer tRsIndex = 0;
            if (cls.isEmpty(tXInfoType)) {
                tXInfoType = "lng";
            }
            String[][] tITakesAry = conf.sp.itakes(tXInfostr, tXInfoType);
            if (tITakesAry != null) {
                tmprstr = "";
                tmpastr = cls.ctemplate(tmpstr, "{@}");
                for (int ti = 0; ti < tITakesAry.length; ti++) {
                    String tNameString = tITakesAry[ti][0];
                    String tValueString = tITakesAry[ti][1];
                    if (cls.isEmpty(tXInfolimit) || cls.cinstr(tXInfolimit, tNameString, ",")) {
                        tRsIndex += 1;
                        tmptstr = tmpastr;
                        tmptstr = tmptstr.replace("{$namestring}", tNameString);
                        tmptstr = tmptstr.replace("{$valuestring}", tValueString);
                        tmptstr = tmptstr.replace("{$name}", encode.htmlencode(tNameString));
                        tmptstr = tmptstr.replace("{$value}", encode.htmlencode(tValueString));
                        tmptstr = tmptstr.replace("{$-genre}", tGenre);
                        tmptstr = tmptstr.replace("{$-baseurl}", tBaseurl);
                        tmptstr = tmptstr.replace("{$-i}", cls.toString(tRsIndex));
                        //**********************************************************************
                        for (int tk = 2; tk < 7; tk++) {
                            int tmodx = tRsIndex % tk;
                            tmptstr = tmptstr.replace("{$-!mod" + tk + "}", cls.toString(tmodx));
                            if (tmodx != 0) {
                                tmptstr = tmptstr.replace("{$-!mod" + tk + "-string}", "");
                            } else {
                                tmptstr = tmptstr.replace("{$-!mod" + tk + "-string}", cls.toString(tOcmode));
                            }
                        }
                        //**********************************************************************
                        tmprstr += tmptstr;
                    }
                }
                tmpstr = cls.ctemplates(tmpstr, "{@}", tmprstr);
            } else {
                tmpstr = "";
            }
            tmpstr = conf.sp.creplace(tmpstr);
        }
        return tmpstr;
    }

    public String repathencode(String argString) {
        String tString = argString;
        if (!cls.isEmpty(tString) && conf.repath.equals("1")) {
            String tgenre = conf.getNGenre();
            String tFullURL = conf.getNURLPre() + conf.getNURL();
            String tSpStr = tgenre + "/";
            String tReURL = cls.getLRStr(tFullURL, tgenre, "leftr");
            tString = tString.replace(tReURL, "{$->>repath}");
        }
        return tString;
    }

    public String repathdecode(String argString) {
        String tString = argString;
        if (!cls.isEmpty(tString)) {
            String tgenre = conf.getNGenre();
            String tFullURL = conf.getNURLPre() + conf.getNURL();
            String tSpStr = tgenre + "/";
            String tReURL = cls.getLRStr(tFullURL, tgenre, "leftr");
            tString = tString.replace("{$->>repath}", tReURL);
        }
        return tString;
    }

    public Boolean sendMail(String argAddress, String argTitle, String argContent) {
        Boolean tbool = false;
        String tAddress = argAddress;
        String tTitle = argTitle;
        String tContent = argContent;
        String tMailUsername = conf.application.getInitParameter("mail_smtpusername");
        if (cls.isEmpty(tMailUsername)) {
            tMailUsername = conf.sp.itake("global.config.mail-smtpusername", "cfg");
        }
        String tMailPwd = conf.application.getInitParameter("mail_smtppassword");
        if (cls.isEmpty(tMailPwd)) {
            tMailPwd = conf.sp.itake("global.config.mail-smtppassword", "cfg");
        }
        String tMailFrom = conf.application.getInitParameter("mail_smtpfrom");
        if (cls.isEmpty(tMailFrom)) {
            tMailFrom = conf.sp.itake("global.config.mail-smtpfrom", "cfg");
        }
        if (cls.isEmpty(tMailFrom)) {
            tMailFrom = tMailUsername;
        }
        String tMailCharset = conf.application.getInitParameter("mail_smtpcharset");
        if (cls.isEmpty(tMailCharset)) {
            tMailCharset = conf.sp.itake("global.config.mail-smtpcharset", "cfg");
        }
        String tMailHost = conf.application.getInitParameter("mail_smtpserver");
        if (cls.isEmpty(tMailHost)) {
            tMailHost = conf.sp.itake("global.config.mail-smtpserver", "cfg");
        }
        try {
            String tReadLineString = "";
            Socket tSocket = new Socket(tMailHost, 25);
            BufferedReader tBufferedReader = new BufferedReader(new InputStreamReader(tSocket.getInputStream()));
            BufferedWriter tBufferedWriter = new BufferedWriter(new OutputStreamWriter(tSocket.getOutputStream()));
            tReadLineString = tBufferedReader.readLine();
            if (tReadLineString.substring(0, 3).equals("220") || tReadLineString.substring(0, 3).equals("250")) {
                tBufferedWriter.write("HELO JTBC\n");
                tBufferedWriter.flush();
                tReadLineString = tBufferedReader.readLine();
                if (tReadLineString.substring(0, 3).equals("250")) {
                    tBufferedWriter.write("AUTH LOGIN\n");
                    tBufferedWriter.flush();
                    tReadLineString = tBufferedReader.readLine();
                    if (tReadLineString.substring(0, 3).equals("334")) {
                        tBufferedWriter.write(encode.base64encode(tMailUsername.getBytes()) + "\n");
                        tBufferedWriter.flush();
                        tReadLineString = tBufferedReader.readLine();
                        if (tReadLineString.substring(0, 3).equals("334")) {
                            tBufferedWriter.write(encode.base64encode(tMailPwd.getBytes()) + "\n");
                            tBufferedWriter.flush();
                            tReadLineString = tBufferedReader.readLine();
                            if (tReadLineString.substring(0, 3).equals("235")) {
                                tBufferedWriter.write("MAIL FROM: <" + tMailFrom + ">\n");
                                tBufferedWriter.flush();
                                tReadLineString = tBufferedReader.readLine();
                                if (tReadLineString.substring(0, 3).equals("250")) {
                                    tBufferedWriter.write("RCPT TO: <" + tAddress + ">\n");
                                    tBufferedWriter.flush();
                                    tReadLineString = tBufferedReader.readLine();
                                    if (tReadLineString.substring(0, 3).equals("250")) {
                                        tBufferedWriter.write("DATA\n");
                                        tBufferedWriter.flush();
                                        tReadLineString = tBufferedReader.readLine();
                                        if (tReadLineString.substring(0, 3).equals("354")) {
                                            tBufferedWriter.write("MIME-Version: 1.0\nContent-type: text/html; charset=" + tMailCharset + "\nTo: <" + tAddress + ">\nFrom: <" + tMailFrom + ">\nSubject: " + tTitle + "\n\n" + tContent + "\n.\n");
                                            tBufferedWriter.flush();
                                            tBufferedWriter.write("QUIT\n");
                                            tBufferedWriter.flush();
                                            tbool = true;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        } catch (Exception e) {
        }
        return tbool;
    }

    public String webBase(String argGenre) {
        String tmpstr = "";
        String tGenre = argGenre;
        Integer tnbasehref = cls.getNum(conf.sp.itake("global.config.nbasehref", "cfg"), 0);
        if (!cls.isEmpty(tGenre)) {
            tnbasehref = cls.getNum(conf.sp.itake("global." + tGenre + ":config.nbasehref", "cfg"), 0);
        }
        if (tnbasehref == 1) {
            tmpstr = conf.sp.itake("global.tpl_public.base", "tpl");
            tmpstr = tmpstr.replace("{$-base}", cls.getLRStr(conf.getNURLPre() + conf.getNURI(), "/", "leftr") + "/");
            tmpstr = conf.sp.creplace(tmpstr);
        }
        return tmpstr;
    }

    public String webMessage(String argMessage) {
        String tMessage = argMessage;
        String tmpstr = conf.sp.itake("global.tpl_common.wfront-message", "tpl");
        tmpstr = tmpstr.replace("{$message}", encode.htmlencode(tMessage));
        tmpstr = conf.sp.creplace(tmpstr);
        return tmpstr;
    }

    public String webMessages(String argMessage, String argBackurl) {
        String tMessage = argMessage;
        String tBackurl = argBackurl;
        String tmpstr = conf.sp.itake("global.tpl_common.wfront-messages", "tpl");
        tmpstr = tmpstr.replace("{$message}", encode.htmlencode(tMessage));
        tmpstr = tmpstr.replace("{$backurl}", encode.htmlencode(tBackurl));
        tmpstr = conf.sp.creplace(tmpstr);
        return tmpstr;
    }

    public common(conf argConf) {
        conf = argConf;
    }
}